﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace XiaLastorm.Sharpshooter.Server
{
	/// <summary>
	/// MainWindow.xaml 的交互逻辑
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
			Server server = (App.Current as App).Server;

			this.Closing += delegate { server.Close(); };

			//对服务器添加事件处理程序
			server.LogAdded += new EventHandler<LogAddedEventArgs>((sender, e) =>
			{
				Dispatcher.BeginInvoke(new Action(() => {
					TbLog.AppendText(e.AddedLog + "\r\n");
				}));
			});
			server.ClientConnected += new EventHandler<ClientEventArgs>((sender, e) =>
			{
				Dispatcher.BeginInvoke(new Action(() => { DgClientList.Items.Add(e.ClientManager); }));
			});
			server.ClientDisconnected += new EventHandler<ClientEventArgs>((sender, e) =>
			{
				Dispatcher.BeginInvoke(new Action(() => { DgClientList.Items.Remove(e.ClientManager); }));
			});

			//启动服务器
			server.Open();
		}

	}
}
